Although the DOORS documentation says that there is a null constant, I think it is conceptual only. I don't think there is a null constant. The null constantThe constant null is used as a polymorphic value to indicate a null value. You can use it for any derived type (see Derived types). You can use it for both assignment to variables and conditional tests on variables. Example
Object obj = null
if (null obj) {
ack "This object is empty"
}
NULL PERMS:There are four perm functions used for assignment:
IMMEDIATE VARIABLES VS. REFERENCE VARIABLES
Types like int, bool, and char are have their content right in the variable.
ILLUSTRATION
real functionReturningRealVersionA() {
// explicitly specify which null function to use
return (real null())
}
real functionReturningRealVersionB() {
// explicitly specify which null function to use
// you can leave off the () and it still works
return (real null)
}
real functionReturningRealVersionC() {
// Even though the function clearly returns real
// DOORS chooses the wrong null() function to execute
return (null());
}
real functionReturningRealVersionD() {
// Even though the function clearly returns real
// DOORS chooses the wrong null() function to execute
// There is no null constant. It is always a function call.
return null;
}
// DOORS (usually) knows which null function to call based on LHS (left hand side of =)
int i1 = 0x04030201;
real r1 = null();
real r2 = 0;
real r3 = null();
string str1 = null();
string str2 = "";
string str3 = null();
int i2 = 0x08070605;
debugLog("int content of 11 = " (int addr_ i1) "");
debugLog("(as int) i1 = " (i1) "");
debugLog("int content of r1 = " (int addr_ r1) "");
debugLog("(as real) r1 = " (r1) "");
debugLog("int content of r2 = " (int addr_ r2) "");
debugLog("(as real) r2 = " (r2) "");
debugLog("int content of r3 = " (int addr_ r3) "");
debugLog("(as real) r3 = " (r3) "");
debugLog("int content of str1 = " (int addr_ str1) "");
debugLog("(as string) str1 = '" (str1) "'");
debugLog("int content of str2 = " (int addr_ str2) "");
debugLog("(as string) str2 = '" (str2) "'");
debugLog("int content of str3 = " (int addr_ str3) "");
debugLog("(as string) str3 = '" (str3) "'");
debugLog("Use (string null()) directly = '" (string null()) "'");
debugLog("int content of 12 = " (int addr_ i2) "");
debugLog("(as int) i2 = " (i2) "");
int anAddr = PtrOps_addressOfVar(i1);
exploreAddresses(anAddr, 8);
debugLog("What does the content of r1 reference?");
exploreAddresses((int addr_ r1) , 2);
debugLog("What does the content of r2 reference?");
exploreAddresses((int addr_ r2) , 2);
debugLog("What does the content of r3 reference?");
exploreAddresses((int addr_ r3) , 2);
debugLog("We see r1 and r3 reference a standard \"null\" real 64 bit area that has real value of 0.0");
debugLog("We see r2 references a newly allocated (with different address) real 64 bit area that has real value of 0.0");
debugLog("Lets give r2 a non-zero value");
r2 = 1.7e308;
exploreAddresses((int addr_ r2) , 2);
debugLog("r2 = " (r2) "");
r2 = functionReturningRealVersionA();
debugLog("[A] r2 = " (r2) "");
r2 = functionReturningRealVersionB();
debugLog("[B] r2 = " (r2) "");
//r2 = functionReturningRealVersionC(); // causes DOORS core dump
//debugLog("[C] r2 = " (r2) "");
SystemAdmin - Wed Oct 26 15:51:18 EDT 2011 |
Re: Null perm and use with real and string variables Such as routinely caste in a return statement: return(Buffer null) Such as routinely caste when used in comparison statements: if (a(1) == string null)
|
Re: Null perm and use with real and string variables llandale - Thu Oct 27 14:26:52 EDT 2011
I'd say the practical advice is:
real r1 = null(); // () optional string str1 = null(); // () optional
// DOORS will crash if you do this (BUG if you ask me)
real thisShouldReturnARealVariationOfNull() {
return null;
}
real r1 = thisShouldReturnARealVariationOfNull();
// DOORS will use the right null() function if you cast
real thisShouldReturnARealVariationOfNull() {
return (real null);
}
real r1 = thisShouldReturnARealVariationOfNull();
string str1 = ""; // str1 contains address of new string descriptor
string str1 = null(); // Here null() returns the address of a stock empty string string str2 = null(); // Here null() returns the address of a stock empty string string str3 = null(); // Here null() returns the address of a stock empty string
|
Re: Null perm and use with real and string variables SystemAdmin - Fri Oct 28 11:58:01 EDT 2011 I'd say the practical advice is:
real r1 = null(); // () optional string str1 = null(); // () optional
// DOORS will crash if you do this (BUG if you ask me)
real thisShouldReturnARealVariationOfNull() {
return null;
}
real r1 = thisShouldReturnARealVariationOfNull();
// DOORS will use the right null() function if you cast
real thisShouldReturnARealVariationOfNull() {
return (real null);
}
real r1 = thisShouldReturnARealVariationOfNull();
string str1 = ""; // str1 contains address of new string descriptor
string str1 = null(); // Here null() returns the address of a stock empty string string str2 = null(); // Here null() returns the address of a stock empty string string str3 = null(); // Here null() returns the address of a stock empty string
If you pass null as a parameter, (although you shouldn't need to) it is wise the put in a cast to be certain the right null() function will be called. The return value of the null() function is what gets is pushed to the parameter list. |